AmigaSoc UK

Java Palava

Unless you've spent the last few years living a life of seclusion in the tibetten foot hills, you can't have escaped hearing about Java in the computer press, and how it's going to revolutionise the computer industry. Whilst they are only too happy to tell you how great Java is, most articles seem to gloss over the important issues, like what exactly is Java and how does it intend to carry out this so-called revolution.


A Simple Java Applet
Quite simply Java is a programming language, however unlike any other programming language Java has been designed to run on any computer platform without requiring any changes being made to the program code itself, something many software developers have been wishing for for many years. More importantly to the Amiga community it means that an Amiga capable of running Java programs would not be limited to programs developed specifically for the Amiga, but could also use the vast range of Java software developed for the PC and Unix market.

With the rapid development and popularity of the Internet, Java has quickly established itself as one of the most popular programming languages. The multitude of different computer platforms connected to the internet and the ability to include java programs, known as applets, as part of a web page have meant that Java has become an essential part of many web pages. Infact some sites on the world wide web will simply not work properly if you do not have a Java enabled browser.

Java's ability to run on any platform is due to the way Java programs are executed. The Java source code is compiled (by a Java compiler, obviously) into what is known as byte-code or j-code. Whereas most compilers optimise the code they produce for the computer platform they are running on, the java compiler produces code in a universal format. This universal j-code can then be run by a Java "virtual-machine" or a "Just In Time" (JIT) compiler. A Java virtual machine provides an environment in which Java code can be executed safely, whereas a JIT compiler rapidly converts the j-code into machine specific code literally milliseconds before the instructions are exectued by the CPU.

Whilst Java claims to be a multi-platform programming language, a Java Virtual Machine or JIT compiler must first be developed for each specific computer platform that wishes to run Java code. This is why, to date, the use of Java is virtually non-existant on the Amiga. Sun Microsystems, the company behind the development of Java have put all their effort into producing Java Virtual Machines for "popular" computer platforms such as Windows and Unix. However, it is possible to license Java from Sun to develop your own Java virtaul machines, and that is exactly what Haage & Partner and Finale Developments have done. In the not to distant future Amiga owners may find themselves with the choice of not one but two Java environments for the Amiga.

Currently, there are only really two options for Amiga owners wishing to run Java, Guava and Kaffe. Both are unlicensed Java implementations. This means that whilst they cannot guarantee to be 100% pure Java, the source code for them is freely distributable. It is possible to get both working under AmigaDos, using ADE (the Amiga Developemt Environment) and under NetBSD by simply (well with a bit of tweeking) compiling the code. Whilst both Kaffe and Guava provide Java development environments to run standalone Java applications, unfortunatly they don't provide any way of running web based Java applets from within a web browser.


Java Applets, such as this golf tutor applet, can only be run in a Java Enabled Browser.


At this point it's probably worth mentioning JavaScript. Despite it's name the only thing Javascipt has in common with Java is the first 4 letters of it's name. Javascript is an interpreted script language, developed by Sun for use in web pages. It lacks most of the features found in a full blown programming language such as Java. Most pages that use Javascript use it for simple cosmetic improvments, animated buttons that change colour when you move your mouse over them and so on. The next revision of Amiga browsers promise JavaScript support as standard. Microsoft decided to implement their own scripting language in their Internet Explorer browser, called JScript, which is similar to, but incompatible with JavaScript. Neither Kaffe nor Guava have any support for JavaScript (or JScript).

Included on this months CD are two versions of Kaffe. A pre-compiled binary of Kaffe 0.8, and the source code for Kaffe 0.9.2. Kaffe 0.8 is compatible with JDK1.0, the first "official" Java release from Sun. However the current release of Java is JDK1.1. Sun released that version 1.0 wasn't quite good enough in certain areas and so made some fundemanatal changes in release 1.1. Most of the changes were in the way the Java VM handled calls to the underlying operating system. Unfortuantly this means that any Java 1.0 code that does anything more exciting than printing a few lines of text will probably break on version 1.1.

Kaffe 0.9.2 is JDK1.1 compatible, but in true source code fashion it`s a real bugger to compile under NetBSD. The problem seems to be caused by the way the "ld" command handles libraries under NetBSD, it can be easily solved by changing the line that reads

LDTAIL = -lm -lc

to read

LDTAIL = -lm

in the Makefile's in the following directories: packages/tjwassoc.co.uk/APIcore/lib, packages/tjwassoc.co.uk/APIzip/lib and kaffe/kaffevm. You may also need to remove the compiler flag -O2 from the Makefile in kaffe/kaffevm if you have less than 32 Megabytes of memory.


This is about as exciting as Kaffe 0.8 gets!
Listing 1 shows a simple Java program that converts uppercase text to lowercase and vice versa.
The reason I'm showing you this program instead of the obligitory "Hello World" program is to illustrate the differences between a language such as Java and the scripting languages such as Perl and Shell scripts we have been looking at previously. If you cast your minds back you will remember that the case conversion script we wrote in chapter 4 was little more than 3 lines of code. You will probably also notice the similarity between the Java code and that of C or C++. Whilst Java may look like C/C++ it lacks many of the fuctions of these languages, such as typedefs and operator overloading. Infact Java acts more like dynamic languages such as Smalltalk and Lisp. Unfortunalty to cover any more then the very basics of Java would require six more tutorials, and this, unfortunalty is my last (for now!). However I have included as much Java documentation as I can get my hands on, on the CD for you to browse at your leasure.

So is Java the future of computing? Maybe, it's certainly growing in popularity day by day, however so far there have been no "killer Applications" written using it. Current Java programs have a tendency to be slower than their machine specific counterparts due to the need to interpret each instruction before it can be exectued, but as CPU's get faster Java will become more widespread. Sun have plans to develop a CPU that will run J-code. Things are not going as well as they might, however. Microsoft, who have licensed Java from Sun have recently produced a version for Windows that produces J-code that will only run on their Virtual Machine, which destroys the entire idea of Java.

And Finally

Also included on this months CD you will find a selection of utilites that didn't quite make it onto any of the other CD's. These include Samba, a utility for mounting networked PC disks and printers and BFFS, an Amiga filesystem which will let you read your NetBSD partitions from within AmigaDos.